It shows how to connect camera to your program by camera IP (Camera IP) address and NIC IP (Export IP) address corresponding to the camera. Enter the IP address in the format of xx.xx.xx.xx.
12 currentsystem = platform.system()
13 if currentsystem ==
'Windows':
14 sys.path.append(os.path.join(os.getenv(
'MVCAM_COMMON_RUNENV'),
"Samples",
"Python",
"MvImport"))
16 sys.path.append(os.path.join(
"..",
"..",
"MvImport"))
17 from MvCameraControl_class
import *
20 if sys.version_info[0] < 3:
22 input_func = raw_input
32 stOutFrame = MV_FRAME_OUT()
33 memset(byref(stOutFrame), 0, sizeof(stOutFrame))
35 ret = cam.MV_CC_GetImageBuffer(stOutFrame, 1000)
36 if None != stOutFrame.pBufAddr
and 0 == ret:
37 print (
"get one frame: Width[%d], Height[%d], nFrameNum[%d]" % (stOutFrame.stFrameInfo.nWidth, stOutFrame.stFrameInfo.nHeight, stOutFrame.stFrameInfo.nFrameNum))
38 nRet = cam.MV_CC_FreeImageBuffer(stOutFrame)
40 print (
"no data[0x%x]" % ret)
44 if __name__ ==
"__main__":
48 MvCamera.MV_CC_Initialize()
50 SDKVersion = MvCamera.MV_CC_GetSDKVersion()
51 print (
"SDKVersion[0x%x]" % SDKVersion)
53 stDevInfo = MV_CC_DEVICE_INFO()
54 stGigEDev = MV_GIGE_DEVICE_INFO()
56 deviceIp =
input_func(
"please input current camera ip : ")
57 netIp =
input_func(
"please input net export ip : ")
59 deviceIpList = deviceIp.split(
'.')
60 stGigEDev.nCurrentIp = (int(deviceIpList[0]) << 24) | (int(deviceIpList[1]) << 16) | (int(deviceIpList[2]) << 8) | int(deviceIpList[3])
62 netIpList = netIp.split(
'.')
63 stGigEDev.nNetExport = (int(netIpList[0]) << 24) | (int(netIpList[1]) << 16) | (int(netIpList[2]) << 8) | int(netIpList[3])
65 stDevInfo.nTLayerType = MV_GIGE_DEVICE
66 stDevInfo.SpecialInfo.stGigEInfo = stGigEDev
72 ret = cam.MV_CC_CreateHandle(stDevInfo)
74 raise Exception(
"create handle fail! ret[0x%x]" % ret)
77 ret = cam.MV_CC_OpenDevice(MV_ACCESS_Exclusive, 0)
79 raise Exception (
"open device fail! ret[0x%x]" % ret)
82 if stDevInfo.nTLayerType == MV_GIGE_DEVICE:
83 nPacketSize = cam.MV_CC_GetOptimalPacketSize()
84 if int(nPacketSize) > 0:
85 ret = cam.MV_CC_SetIntValue(
"GevSCPSPacketSize",nPacketSize)
87 print (
"Warning: Set Packet Size fail! ret[0x%x]" % ret)
89 print (
"Warning: Get Packet Size fail! ret[0x%x]" % nPacketSize)
92 ret = cam.MV_CC_SetEnumValue(
"TriggerMode", MV_TRIGGER_MODE_OFF)
94 raise Exception (
"set trigger mode fail! ret[0x%x]" % ret)
97 ret = cam.MV_CC_StartGrabbing()
99 raise Exception (
"start grabbing fail! ret[0x%x]" % ret)
103 hThreadHandle = threading.Thread(target=work_thread, args=(cam,
None))
104 hThreadHandle.start()
106 raise Exception (
"error: unable to start thread")
108 print (
"press Enter key to stop grabbing.")
115 ret = cam.MV_CC_StopGrabbing()
117 raise Exception (
"stop grabbing fail! ret[0x%x]" % ret)
120 ret = cam.MV_CC_CloseDevice()
122 raise Exception (
"close deivce fail! ret[0x%x]" % ret)
125 cam.MV_CC_DestroyHandle()
126 except Exception
as e:
128 cam.MV_CC_CloseDevice()
129 cam.MV_CC_DestroyHandle()
132 MvCamera.MV_CC_Finalize()